/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
///    Worldly Variables     ///
*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

var
	version = "v0.16"

	/* Lists */
	MuteList = list()
	Banned = list()

	list/Admins = list("mikau","divinetraveller","audeuro","sinfall","stephen001","silkwizard","superantx")
	list/Moderators = list()

	Reboot = FALSE
	RebootTimer = 60

	list/Everyone = list()
	list/Available = list()
	list/Busy = list()
	list/Away = list()
	list/Idle = list()

	list/TelnetInfo = null

	/* Main Chat */
	Welcome = {"
	<div style="text-align: center; font-weight: bold; font-size: 16pt;">Welcome to The Saloon.</div><center>( [version] )</center><div style="text-align: center; font-weight: bold; font-size: 12pt;">
	<a href="http://www.byond.com/games/Mikau/Saloon">Hub</a> |
	<a href="byond://?action=patchnotes">Patch Notes</a> |
	<a href="byond://?action=readme">Readme</a></div>"}

	Bot_Color = "#083C76"

	ConversationTopic = "No topic"
	LengthLimit = 350
	MaxInputs = 3
	IdleTime = 15 // minutes


/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
///    Worldly Worldness     ///
*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

world
	name = "The Saloon"
	hub = "mikau.saloon"
	hub_password= "hcHSIYhT3wpYBxno"

	New()
		..()

		// Load World related information
		LoadTheWorld()

	Del()

		// Save World related information
		SaveTheWorld()

		// Cut out all lists.
		Available.Cut()
		Busy.Cut()
		Away.Cut()
		Idle.Cut()

		// Delete every showcode
		fdel("ShowCode/")

		..()


/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
///    Worldly Procedures    ///
*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/


proc

	// Saves all world information into a Config file.
	SaveTheWorld()

		fdel("Config.sav")
		var/savefile/F2 = new("Config.sav")

		F2["MuteList"]<<MuteList
		F2["Banned"]<<Banned

		//F2["Moderators"]<<Moderators

		F2["TelnetInfo"]<<TelnetInfo
		F2["Topic"]<<ConversationTopic

	// Loads all world information from a Config file.
	LoadTheWorld()
		if(fexists("Config.sav"))
			var/savefile/F2 = new("Config.sav")

			F2["MuteList"]>>MuteList
			F2["Banned"]>>Banned

			//F2["Moderators"]>>Moderators
			//if(Moderators == null) Moderators = list()

			F2["TelnetInfo"]>>TelnetInfo
			F2["Topic"]>>ConversationTopic


	// Send a message to all clients as the bot.
	System_WorldMessage(var/message as text)
		for(var/client/C)
			var/Time = C.getTime()
			C<<"<b>\[</b>[Time]<b>\] <font color='[html_encode(Bot_Color)]'>@Wench</font></b>: <font color='red'>[message]</font>"

	// Send a message to all admins as the bot.
	System_AdminMessage(var/message as text)
		for(var/client/C)
			if(C.ckey in Admins)
				C<<"<font color='red'>[message]</font>"

	// Sort a list?
	BubbleSort(list/L)
		var/client/A
		var/client/B
		for(var/outer=1,outer<L.len,++outer)
			for(var/inner=L.len,inner>outer,--inner)
				A=L[inner]
				B=L[inner-1]
				if((A.key)<(B.key))
					L[inner]=B
					L[inner-1]=A

	InsertSort(list/L)
		for(var/j in 2 to L.len)
			var/key = L[j]
			var/i = j-1
			while(i>0 && sorttextEx("[L[i]]", "[key]") == -1)
				L[i+1] = L[i]
				i--
			L[i+1] = key

	updateUsers()
		for(var/client/C in Everyone)
			C.displayUsers()

client/verb

	displayUsers()
		set hidden = 1
		var/ChattersList = 2

		if(Available.len > 1) InsertSort(Available)
		for(var/client/C in Available)
			winset(src,"Main_Userlist.WhoGrid","current-cell=1,[ChattersList]")
			winset(src,"Main_Userlist.WhoGrid","style=\"body{color:[C.Grid_Color];font-weight:[C.Font_Weight];font-size:12px;}")
			src<< output(C.mob,"Main_Userlist.WhoGrid")
			ChattersList++

		if(Busy.len > 1) InsertSort(Busy)
		for(var/client/C in Busy)
			winset(src,"Main_Userlist.WhoGrid","current-cell=1,[ChattersList]")
			winset(src,"Main_Userlist.WhoGrid","style=\"body{color:gray;font-weight:lighter;font-size:12px;}")
			src<< output(C.mob,"Main_Userlist.WhoGrid")
			ChattersList++

		if(Away.len > 1) InsertSort(Away)
		for(var/client/C in Away)
			winset(src,"Main_Userlist.WhoGrid","current-cell=1,[ChattersList]")
			winset(src,"Main_Userlist.WhoGrid","style=\"body{color:gray;font-weight:lighter;font-size:12px;}")
			src<< output(C.mob,"Main_Userlist.WhoGrid")
			ChattersList++

		if(Idle.len > 1) InsertSort(Idle)
		for(var/client/C in Idle)
			winset(src,"Main_Userlist.WhoGrid","current-cell=1,[ChattersList]")
			winset(src,"Main_Userlist.WhoGrid","style=\"body{color:gray;font-weight:lighter;font-size:12px;}")
			src<< output(C.mob,"Main_Userlist.WhoGrid")
			ChattersList++

		winset(src,"Main_Userlist.WhoGrid","cells=1x[ChattersList-1]")